from yaml import safe_load
import logging
import base64

class Action:
    def __init__(self):
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')
        self.log = logging.getLogger(__name__)

    def load_yaml(self, file='./data/case.yml'):
        try:
            with open(file, 'r') as f:
                return safe_load(f)
        except Exception:
            self.log.error("yaml读取失败！")
            raise

    # 获取验证码接口/captchaImage返回的img字段转成图片
    def base64ToImage(self, text):
        imgdata = base64.b64decode(text)
        with open('captchaImage.jpg', 'wb') as f:
            f.write(imgdata)
